/*
 * @Author: 王雁鹏
 * @Date: 2023-04-27 07:25:22
 * @LastEditTime: 2023-07-30 16:19:11
 * @LastEditors: 
 * @Description: 
 * @FilePath: \expressf:\web-vue\bs-nodejs-background-code\routes\files.js
 * -------------------------------------
 */
var express = require('express');
var router = express.Router();
let path = `F:/手机内存备份/video/`
const Files = require('../utils/files');
let files = new Files()
let fn = (path) => {
    files.readdir(path, (err, data) => {
        data.forEach(item => {
            files.stat(`${path}/${item}`, (err, data) => {
                if (data.isFile()) {
                    if (/.mp4$/.test(item)) {
                        files.rename(`${path}/${item}`, `F:/手机内存备份/video/${item}`, (err) => {
                            if (err) throw new Error(err);
                        })
                    }
                }
                if (data.isDirectory()) {
                    fn(`${path}/${item}`)
                }
            })
        });
    })
}
// fn(path)
router.get('/name', function (req, res, next) {
    res.send({ code: 200, data: "文件迁移完成" });
})


module.exports = router